package top.jacktgq.itheima.netty.protocol_design.groupchat.message;

import io.netty.channel.ChannelHandlerContext;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Data
@ToString(callSuper = true)
@Slf4j
public class ChatResponseMessage extends AbstractResponseMessage {

    private String from;
    private String content;

    public ChatResponseMessage() {

    }

    public ChatResponseMessage(boolean success, String reason) {
        super(success, reason);
    }

    public ChatResponseMessage(String from, String content) {
        this.from = from;
        this.content = content;
    }

    @Override
    public int getMessageType() {
        return ChatResponseMessage;
    }

    @Override
    public void handle(ChannelHandlerContext ctx) {
        // 如果发送人和消息都为空，说明是服务器发来的消息，用户不存在或者不在线
        if (from == null) {
            log.debug(getReason());
        } else {
            log.debug("[私聊]" + from + " 说：{}", content);
        }
    }
}
